/*
 * Wazuh Vulnerability Scanner - Unit Tests
 * Copyright (C) 2015, Wazuh Inc.
 * February 29, 2024.
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public
 * License (version 2) as published by the FSF - Free Software
 * Foundation.
 */

#include "globalData_test.hpp"
#include "globalData.hpp"

TEST(GlobalDataTest, StoreAndGetVendorMap)
{
    const std::string vendorMap {
        R"({"contains":[{"@ubuntu.com":"canonical"}],"format":[{"pypi":"pypi"},{"npm":"npm"}],"prefix":[{"Canonical":"canonical"},{"Ubuntu":"canonical"},{"CentOS":"redhat"}]})"};

    nlohmann::json vendorMapJson = nlohmann::json::parse(vendorMap);

    GlobalData::instance().vendorMaps(vendorMapJson);
    EXPECT_STREQ(GlobalData::instance().vendorMaps().dump().c_str(), vendorMap.c_str());
}

TEST(GlobalDataTest, StoreAndGetOsCpeMap)
{
    const std::string osCpeRules {R"#({"fedora":"fedoraproject:fedora:$(MAJOR_VERSION)"})#"};

    nlohmann::json osCpeRulesJson = nlohmann::json::parse(osCpeRules);

    GlobalData::instance().osCpeMaps(osCpeRulesJson);
    EXPECT_STREQ(GlobalData::instance().osCpeMaps().dump().c_str(), osCpeRules.c_str());
}

TEST(GlobalDataTest, StoreAndGetManagerName)
{
    const std::string managerName {"wazuh"};

    GlobalData::instance().managerName(managerName);
    EXPECT_STREQ(GlobalData::instance().managerName().data(), managerName.c_str());
}
